package controleur;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;

public class TransactionForm extends ActionForm {
	
	private static final long serialVersionUID = 1L;
	
	String nom;
	String prenom;
	String email;
	String ville;
	String cp;
	String adresse;
	int annee;
	int mois;
	String crypto;
	String num_carte;
	String type_carte;
	
	
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getPrenom() {
		return prenom;
	}
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getVille() {
		return ville;
	}
	public void setVille(String ville) {
		this.ville = ville;
	}
	public String getCp() {
		return cp;
	}
	public void setCp(String cp) {
		this.cp = cp;
	}
	public String getAdresse() {
		return adresse;
	}
	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}
	public int getAnnee() {
		return annee;
	}
	public void setAnnee(int annee) {
		this.annee = annee;
	}
	public int getMois() {
		return mois;
	}
	public void setMois(int mois) {
		this.mois = mois;
	}
	public String getCrypto() {
		return crypto;
	}
	public void setCrypto(String crypto) {
		this.crypto = crypto;
	}
	public String getNum_carte() {
		return num_carte;
	}
	public void setNum_carte(String num_carte) {
		this.num_carte = num_carte;
	}
	public String getType_carte() {
		return type_carte;
	}
	public void setType_carte(String type_carte) {
		this.type_carte = type_carte;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (nom==null || nom.length()==0) {
			errors.add("nom", new ActionMessage("erreur.nom.obligatoire"));
		}
		if (prenom==null || prenom.length()==0) {
			errors.add("prenom", new ActionMessage("erreur.prenom.obligatoire"));
		}
		if (email==null || email.length()==0) {
			errors.add("email", new ActionMessage("erreur.email.obligatoire"));
		}
		if (crypto==null || crypto.length()==0) {
			errors.add("crypto", new ActionMessage("erreur.crypto.obligatoire"));
		}
		if (num_carte==null || num_carte.length()==0) {
			errors.add("num_carte", new ActionMessage("erreur.num_carte.obligatoire"));
		}
		System.out.println("num_carte");
/*		Pattern pattern_carte = Pattern.compile("{16}\\d");
	
		Matcher matcher = pattern_carte.matcher(num_carte);
		if (num_carte.length()!=16 || !matcher.matches()) {
			errors.add("num_carte", new ActionMessage("erreur.num_carte.invalide"));
		}
		Pattern pattern_crypto = Pattern.compile("{3}\\d");
		matcher = pattern_crypto.matcher(crypto);
		if (crypto.length()!=3 || !matcher.matches()) {
			errors.add("crypto", new ActionMessage("erreur.crypto.invalide"));
		}
		*/
		return errors;
	}
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		nom = null;
		prenom = null;
		email = null;
		ville = null;
		cp = null;
		adresse = null;
		annee = 0;
		mois = 0;
		crypto = null;
		num_carte = null;
		type_carte = null;
	}
}